package com.platform.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.platform.service.impl.StandingsServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import com.platform.entity.StandingsEntity;
import com.platform.service.StandingsService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;

/**
 * Controller
 *
 * @author ocean
 * @email 1141736487@qq.com
 * @date 2019-03-15 16:00:12
 */
@RestController
@RequestMapping("standings")
public class StandingsController {
    @Autowired
    private StandingsServiceImpl standingsService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("standings:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<StandingsEntity> standingsList = standingsService.queryList(query);
        int total = standingsService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(standingsList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 根据编码查
     * @param code
     * @return
     */
    @RequestMapping("/infoByType/{code}")
    @RequiresPermissions("standings:infobytype")
    public R infoByType(@PathVariable("code")String code){
        StandingsEntity standings = standingsService.infoByCode(code);
        return R.ok().put("standings", standings);

    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("standings:info")
    public R info(@PathVariable("id") Integer id) {
        StandingsEntity standings = standingsService.queryObject(id);

        return R.ok().put("standings", standings);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("standings:save")
    public R save(@RequestBody StandingsEntity standings) {
        standingsService.save(standings);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("standings:update")
    public R update(@RequestBody StandingsEntity standings) {
        standingsService.update(standings);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("standings:delete")
    public R delete(@RequestBody Integer[] ids) {
        standingsService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<StandingsEntity> list = standingsService.queryList(params);

        return R.ok().put("list", list);
    }
}
